package com.naiterui.ehp.bp.support.interceptor;

import java.io.IOException;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.lang.NonNull;

import lombok.extern.slf4j.Slf4j;

/**
 * RestTemplate需要使用此拦截器增加内网请求
 *
 * @author wangzehao
 * @date 2018/10/3 4:23 PM
 * @since 1.0.0
 */
@Slf4j
public class InnerClientHttpRequestInterceptor implements ClientHttpRequestInterceptor {

    @Override
    public ClientHttpResponse intercept(@NonNull HttpRequest request, @NonNull byte[] body,
                                        @NonNull ClientHttpRequestExecution execution) throws IOException {
        HttpHeaders headers = request.getHeaders();
        headers.add("X-inner", "1");
        log.debug("增加内网请求");
        return execution.execute(request, body);
    }
}
